/*
 * Copyright (C) 2004, Velocityme Partnership
 * RoleValueActionForm.java
 *
 * Created on 09 October 2004, 06:13
 */

package com.velocityme.www.actionforms.nodeactionforms;

import com.velocityme.entity.Role;
import com.velocityme.enums.Permission;
import com.velocityme.session.KeyLocal;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author  Robert
 */
public class RoleActionForm extends NodeActionForm {
    
    private boolean recursive;
    private boolean[] enabled;
    private Permission[] permissionArray;
    private HashSet<Permission> permissions = new HashSet<Permission>();

    public void extractRole(KeyLocal key, Role role) {
        extractNode(role);
        role.setRecursive(recursive);
        role.setPermissions(permissions);
    }


    @Override
    public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
        recursive = false;
        permissions = new HashSet<Permission>();
        permissionArray = Permission.sortedValues();
    }
    
    public boolean isRecursive() {
        return recursive;
    }
    
    public void setRecursive(boolean recursive) {
        this.recursive = recursive;
    }

    public void setEnabled(int index, boolean enabled) {
        permissions.add(permissionArray[index]);
    }

    public void setEnabled(boolean[] enabled) {
        this.enabled = enabled;
    }

    public boolean getEnabled(int index) {
        return enabled[index];
    }

}
